package com.wanmait.recruitment.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.recruitment.mapper.TagsMapper;
import com.wanmait.recruitment.pojo.Tags;
import com.wanmait.recruitment.service.TagsService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
@Transactional(rollbackFor = Exception.class)
public class TagsServiceImpl implements TagsService {
    @Resource
    private TagsMapper tagsMapper;
    @Override
    @CacheEvict(value = "tagsCache",allEntries = true)
    public void insert(Tags object) {
        tagsMapper.insertSelective(object);
    }

    @Override
    @CacheEvict(value = "tagsCache",allEntries = true)
    public void delete(Integer id) {
        tagsMapper.updateEnable(id);
    }

    @Override
    public void delete(String ids) {
        String idArr[] = ids.split(",");
        List<Integer> list = new ArrayList<>();
        for (int i=0;i<idArr.length;i++){
            list.add(Integer.parseInt(idArr[i]));
        }
        tagsMapper.batchDel(list);
    }

    @Override
    @CacheEvict(value = "tagsCache",allEntries = true)
    public void update(Tags object) {
        tagsMapper.updateByPrimaryKeySelective(object);
    }

    @Override
    public Tags findById(Integer id) {
        return null;
    }

    @Override
    @Cacheable("tagsCache")
    public List<Tags> findAll() {
        return tagsMapper.findAll();
    }

    @Override
    public List<Tags> findAll(Tags object) {
        return null;
    }

    @Override
    public PageInfo<Tags> findPage(int pageNum, int pageSize) {
        return null;
    }

    @Override
    @Cacheable("tagsCache")
    public List<Tags> findType() {
        return tagsMapper.findType();
    }

    @Override
    @Cacheable("tagsCache")
    public PageInfo<Tags> findPage(Tags tags, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Tags> tags1 = tagsMapper.findOne(tags);
        PageInfo<Tags> tagsPageInfo = new PageInfo<>(tags1);
        return tagsPageInfo;
    }
}
